package kea.stopwords;



import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Hashtable;

/**
 * Class that can test whether a given string is a stop word.
 * Lowercases all words before the test.
 *
 * @author Eibe Frank (eibe@cs.waikato.ac.nz)
 * @version 1.0
 */
public class StopwordsPortugese extends Stopwords {

	/**
	 *
	 */
	private static final long serialVersionUID = 1L;


	/** The hashtable containing the list of stopwords */
	private static Hashtable m_Stopwords = null;

        private static String rootPath;

        /**
         * Get the value of rootPath
         *
         * @return the value of rootPath
         */
        public static String getRootPath() {
            return rootPath;
        }

        /**
         * Set the value of rootPath
         *
         * @param rootPath new value of rootPath
         */
        public static void setRootPath(String absPath) {
          StopwordsPortugese.rootPath = absPath;
        }

        public String getStopwordsType() {
            return "portugese-stop";
        }

        public static String GetStopwordsType() {
            return "portugese-stop";
        }

        public StopwordsPortugese() {

		if (m_Stopwords == null) {
			m_Stopwords = new Hashtable();
			Double dummy = new Double(0);
			File txt = new File(getRootPath() + "data/stopwords/stopwords_pt.txt");
			InputStreamReader is;
			String sw = null;
			try {
				is = new InputStreamReader(new FileInputStream(txt), "ISO-8859-1");
				BufferedReader br = new BufferedReader(is);
				while ((sw=br.readLine()) != null)  {
                                        sw = sw.trim();
                                        System.out.println("STopwords-PT: " + sw+"CHK");
					m_Stopwords.put(sw, dummy);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}

		}
        }


//	static {
//
//		if (m_Stopwords == null) {
//			m_Stopwords = new Hashtable();
//			Double dummy = new Double(0);
//			File txt = new File(getRootPath() + "data/stopwords/stopwords_pt.txt");
//			InputStreamReader is;
//			String sw = null;
//			try {
//				is = new InputStreamReader(new FileInputStream(txt), "ISO-8859-1");
//				BufferedReader br = new BufferedReader(is);
//				while ((sw=br.readLine()) != null)  {
//                                        sw = sw.trim();
//                                        System.out.println("STopwords: " + sw+"CHK");
//					m_Stopwords.put(sw, dummy);
//				}
//			} catch (Exception e) {
//				e.printStackTrace();
//			}
//
//		}
//	}

	/**
	 * Returns true if the given string is a stop word.
	 */
	public boolean isStopword(String str) {

//                if(m_Stopwords.containsKey(str.trim().toLowerCase())) System.out.println(str + " is a stopword-PT");
		return m_Stopwords.containsKey(str.trim().toLowerCase());
	}
}


